/*
 * Created: Author: Aléx Carvalho / Date: Feb 20, 2015
 * 
 * Changed: $Author: ac280593@gmail.com $ / $Date: 2015-06-11 04:31:49 +0000 (Thu, 11 Jun 2015) $
 */
package com.cpm.view.zk.field;

import com.cpm.aggregate.Attribute;
import org.zkoss.zk.ui.HtmlBasedComponent;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Doublebox;

public class DoubleField extends AbstractInputField<Double> {

    private final Doublebox doublebox = new Doublebox();

    public void setStyle(String style) {
        doublebox.setStyle(style);
    }

    public void setWidth(String width) {
        doublebox.setWidth(width);
    }

    @Override
    public Double getValue() {
        return doublebox.getValue();
    }

    @Override
    public void setValue(Double value) {
        doublebox.setValue(value);
    }

    public void setValue(Attribute<Double> target) {
        if (target != null) {
            doublebox.setValue(target.getValue());
        }
    }

    @Override
    public boolean isEnabled() {
        return !doublebox.isDisabled();
    }

    @Override
    public void setEnabled(boolean enable) {
        doublebox.setDisabled(!enable);
    }

    @Override
    public HtmlBasedComponent getElement() {
        return doublebox;
    }

    public void addEventListener(String event, EventListener listener) {
        if (listener != null) {
            doublebox.addEventListener(event, e
                    -> listener.onEvent(e)
            );
        }
    }

}
